import {useEffect} from 'react'
import { Route,Routes,useNavigate } from "react-router-dom";
import routerList from './router/index';
import {useLocation} from 'react-router-dom'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const renderRouter=(list: any)=>{
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return list.map((item:any)=>{
    return <Route path={item.path} key={item.path} element={<item.element></item.element>}>
       {item.children&&renderRouter(item.children)}
    </Route>
  })
}
const App = () => {
  const navigate = useNavigate()
    const location = useLocation()
    const shouwei=(list:any)=>{
      list.forEach((item:any)=>{
        if(item.tokens){
          const token = localStorage.getItem('token');
          if(!token){
            navigate('/home/index')
          }
        }
        if(item.children){
          shouwei(item.children)
        }
      })
    }
    useEffect(()=>{
      shouwei(routerList)
    },[location.pathname])
  return (
    <div>
        <Routes>
          {renderRouter(routerList)}
        </Routes>
    </div>
  )
}
export default App
